#用协程实现计算平均数函数
def coro_avg():
    total = 0
    length = 0
    while True:
        #处理异常
        try:
            value = yield total / length
        except ZeroDivisionError:
            value = yield 0
<<<<<<<
        total += value
        length += 1
=======
        total += value
        length += 1
>>>>>>> origin/master

my_avg = coro_avg()
# 预激
next(my_avg)
print(my_avg.send(2))
print(my_avg.send(3))
print(my_avg.send(4))


#缩写一个asyncio异步程序
import asyncio
import time
import requests


async def say_after_time(delay, what):

    await asyncio.sleep(delay)
    print(what)


async def main():
    print(f"开始时间为： {time.time()}")
    await say_after_time(1, "hello")
    await say_after_time(2, "world")
    print(f"结束时间为： {time.time()}")


#获取消息队列
#loop = asyncio.get_event_loop()
#包装任务
#task_array = []
#for i in range(10):
    #task_array.append(i)
#循环访问事件来完成异步的消息维护
#loop.run_until_complete(asyncio.wait(*task_array))
#关闭事件循环
#loop.close
